<script language="javascript" type="text/javascript" src="p_igreja/valida_form.js"></script>
<?php 

include "p_usuario/valida_credenciais.php";
$valCr = new valida_credenciais();
//$nivel define o array de acessos, ou seja, os grupos que podem acessar essa pagina

$nivel = array(1,2,3);
if(!($valCr->validar($nivel))){
	header('Location: index.php?p=denied');
}


$id = $_GET['i'];
$resul = mysql_query("SELECT * FROM igrejas WHERE igrejas.id = $id");
$igreja = mysql_fetch_array($resul);

$resultado = mysql_query("SELECT * FROM membros WHERE membros.id = {$igreja['membro_id']}");
$membro = mysql_fetch_array($resultado);

$res = mysql_query("SELECT * FROM contatos WHERE contatos.id = {$igreja['contato_id']}");
$contato = mysql_fetch_array($res);

$r = mysql_query("SELECT * FROM enderecos WHERE enderecos.id = {$igreja['endereco_id']}");
$endereco = mysql_fetch_array($r);

?>
<div class="form bg-warning">
	<div class="row">
		<div class="col-md-12">
			<div class="page-header">
				<h2>Editar dados da Igreja</h2>
			</div>
		</div>
	</div>
	<div class="row">
	<div class="col-md-3">
			<div class="actions">
				<div class="panel panel-default">
					<div class="panel-heading"><h5>OpÃ§Ãµes</h5></div>
						<div class="panel-body">
							<ul class="nav nav-pills nav-stacked">
								<li><a href="index.php?p=igrejas">Listar Igrejas</a></li>
								
							</ul>
						</div>
					</div>
				</div>			
		</div><!-- end col md 3 -->
		<div class="col-md-9">
		<!-- HEAD DE FORMULÃ�RIO -->
		<div class="panel panel-default">
			<div class="panel-heading"><h5>FormulÃ¡rio de ediÃ§Ã£o de Cadastro de igreja</h5></div>
			<div class="panel-body">
			<!-- FORMULÃ�RIO -->
			<form  method="post" name="form1" action="p_igreja/editar.php" enctype="multipart/form-data">
				<div class="row">
					<div class="col-md-12 form-group"><h6>(<span class="text-danger">*</span>) Campos de preenchimento obrigatÃ³rio.</h6></div>
				</div>
				<input type="hidden" name="idigreja" value="<?php echo $igreja['id'];?>">
				<input type="hidden" name="idcont" value="<?php echo $igreja['contato_id'];?>">
				<input type="hidden" name="idend" value="<?php echo $igreja['endereco_id'];?>">
				<div class="row">
					<div class="form-group col-md-6">
						<label for="status">SituaÃ§Ã£o da Igreja (<span class="text-danger">*</span>)</label>
    					<select name="status" class="form-control">
		          			<?php if($igreja['i_status'] == 1){ ?>
								<option value="<?php echo $igreja['i_status']; ?>" selected>Igreja Ativa</option>
								<option value="0">Igreja Inativa</option>
							<?php } else{?>
								<option value="<?php echo $igreja['i_status']; ?>" selected>Igreja Inativa</option>
								<option value="1">Igreja Ativa</option>
							<?php }?>
		          		</select>
		          	</div>
				</div>
				
				<div class="row">
					<div class="form-group col-md-9">
						<label for="nome">Igreja ou Congregacao (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" name="igreja" id="igreja" value="<?php echo $igreja['igreja'];?>">
					</div>
				</div>
				<div class="row">	
					<div class="form-group col-md-8">
						<label for="descricao" title="Descricao da Igreja">DescriÃ§Ã£o (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="descricao" name="descricao" maxlength="11" value="<?php echo $igreja['i_descricao'];?>">
					</div>
				</div>
				<div class="row">	
					<div class="form-group col-md-7">
							<label for="membro_id">Pastor ResponsÃ¡vel (<span class="text-danger">*</span>)</label>
	    					<select name="membro_id" id="membro_id" class="form-control">
			          			<option value='selecione'>Selecione...</option>
								<?php
									$query = mysql_query("SELECT id, membro, tipo_membro_id FROM membros WHERE membros.tipo_membro_id = 1");
									while($lista = mysql_fetch_array($query)) { 
										if($lista['id'] == $membro['id']){?> 
											<option value="<?php echo $lista['id']; ?>" selected><?php echo $lista['membro']; ?></option>
										<?php }else{?>
										<option value="<?php echo $lista['id']; ?>"><?php echo $lista['membro']; ?></option>
								<?php }}?>
			          		</select>
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-7">
						<label for="tipo_igr">Tipo de Igreja (<span class="text-danger">*</span>)</label>
    					<select name="tipo-igreja" id="tipoigreja" class="form-control">
		          			<option value='selecione'>Selecione...</option>
							<?php
									$query = mysql_query("SELECT id, tipo_igr FROM tipo_igrejas");
									while($lista = mysql_fetch_array($query)) { 
										if($lista['id'] == $igreja['tipo_igreja_id']){?> 
											<option value="<?php echo $lista['id']; ?>" selected><?php echo $lista['tipo_igr']; ?></option>
										<?php }else{?>
										<option value="<?php echo $lista['id']; ?>"><?php echo $lista['tipo_igr']; ?></option>
								<?php }}?>
		          		</select>
					</div>
				</div>
				
				<h5 class="page-header">Contato</h5>
				<div class="row">
					<div class="form-group col-md-4">
						<label for="tel-fixo">Telefone Fixo (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="telfixo" name="tel-fixo" placeholder="(67) 3232-5511"  onkeypress="MascaraTelefone(form1.telfixo);" maxlength="14" onBlur="ValidaTelefone(form1.telfixo);" value="<?php echo $contato['tel_fixo'];?>">
					</div>
					<div class="form-group col-md-4">
						<label for="tel-cel">Telefone Celular (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="telcel" name="tel-cel" placeholder="(67) 9944-5511" maxlength="14" onkeypress="MascaraTelefone(form1.telcel);" onBlur="ValidaTelefone(form1.telcel);" value="<?php echo $contato['tel_cel'];?>">
					</div>
					<div class="form-group col-md-4">
						<label for="tel-aux">Telefone Auxiliar</label>
    					<input type="text" class="form-control" id="telaux" name="tel-aux" placeholder="(67) 0000-0000" maxlength="14" onkeypress="MascaraTelefone(form1.telaux);" value="<?php echo $contato['tel_aux'];?>">
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-6">
						<label for="email">Email (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="email" name="email" placeholder="email@email.com" value="<?php echo $contato['email'];?>">
					</div>
					<div class="form-group col-md-6">
						<label for="email-aux">Email Auxiliar</label>
    					<input type="text" class="form-control" id="emailaux" name="email-aux" placeholder="email@email.com" value="<?php echo $contato['email_aux'];?>">
					</div>
				</div>
				<h5 class="page-header">EndereÃ§o</h5>
				<div class="row">
					<div class="form-group col-md-8">
						<label for="rua">Rua (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="rua" name="rua" value="<?php echo $endereco['rua'];?>">
					</div>
					<div class="form-group col-md-4">
						<label for="rua">NÃºmero (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="numero" name="numero" maxlength="5" value="<?php echo $endereco['numero'];?>">
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-6">
						<label for="ref">ReferÃªncia</label>
    					<input type="text" class="form-control" id="ref" name="ref" value="<?php echo $endereco['referencia'];?>">
					</div>
					<div class="form-group col-md-6">
						<label for="compl">Complemento</label>
    					<input type="text" class="form-control" id="compl" name="compl" value="<?php echo $endereco['complemento'];?>">
					</div>
				</div>
				<div class="row">
					<div class="form-group col-md-6">
						<label for="bairro">Bairro (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="bairro" name="bairro" value="<?php echo $endereco['bairro'];?>">
					</div>
					<div class="form-group col-md-2">
						<label for="cep">CEP (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="cep" name="cep" maxlength="10" onkeypress="MascaraCep(form1.cep);" onBlur="ValidaCep(form1.cep)" value="<?php echo $endereco['cep'];?>">
					</div>
					
				</div>
				<div class="row">
					<div class="form-group col-md-6">
						<label for="cidade">Cidade (<span class="text-danger">*</span>)</label>
    					<input type="text" class="form-control" id="cidade" name="cidade" value="<?php echo $endereco['cidade'];?>">
					</div>
					<div class="form-group col-md-6">
						<label for="estado">Estado (<span class="text-danger">*</span>)</label>
    					<select name="estado" class="form-control">
		          			<option value='selecione'>Selecione...</option>
		          			<?php
									$query = mysql_query("SELECT id, estados.estado FROM estados");
									while($lista = mysql_fetch_array($query)) { 
									if($lista['id'] == $endereco['estado_id']){?> 
										<option value="<?php echo $lista['id']; ?>" selected><?php echo $lista['estado']; ?></option>
										<?php }else{?>
										<option value="<?php echo $lista['id']; ?>"><?php echo $lista['estado']; ?></option>
								<?php }}?>
		          		</select>
					</div>
				</div>
				
				<br>
				<div class="row">
					<div class="form-group col-md-2">
						<input type="submit" value="Salvar" class="btn btn-default" name="enviar" onclick="return valida()" >
					</div>
				</div>
			</form>
			</div>
		</div>

		</div><!-- end col md 12 -->
	</div><!-- end row -->
</div>
			